<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>
<style>
    .table {
        width: 98%;
        border-collapse: collapse;
        border: 1px solid rgb(204, 204, 204);
        margin: 1%;
    }

    .table th,
    .table td {
        border: 1px solid rgb(204, 204, 204);
    }
</style>

<body>
    <header class="aui-bar aui-bar-nav" style="position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            派工
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <div class="aui-searchbar" id="search" style="position: relative;">
            <div class="aui-searchbar-input aui-border-radius">
                <i class="aui-iconfont aui-icon-search">人员名称</i>
                <div class="aui-searchbar-input">
                    <form>
                        <input type="search" placeholder="请输入搜索的人员名称" id="description">
                    </form>
                </div>
            </div>
            <div class="aui-btn aui-btn-primary" style="margin-right: 0.5rem;background-color: #03a9f4"
                onclick="doSearch()">搜索</div>
        </div>

        <table class="table" style="border: 1px solid gray;" cellspacing="0" cellpadding="0">
            <thead>
                <tr style="text-align: center;font-size: 15px;height: 32px;">
                    <td algin='center' style="width:5%"><input name='main' type='checkbox' id="allboxs"
                            style="display: none;" onclick="allcheck()" /></td>
                    <td algin='center' style="width:25%; display: none;">人员编码</td>
                    <td algin='center' style="width:25%">人员</td>
                    <td algin='center' style="width:30%">状态</td>
                    <td algin='center' style="width:20%">待维修</td>
                    <td algin='center' style="width:20%">维修中</td>
                </tr>
            </thead>
            <tbody id="tbodyHtml">
            </tbody>
        </table>
    </div>
    <footer class="aui-bar aui-bar-tab ui-selectee">
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="save()">提交</div>
    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var equipCode = ""; //设备编码
    //初始化
    apiready = function () {
        $("#equipCode").focus();
        idSelector = "equipCode";
        doSearch();
    }
    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }
    //扫描
    function doScan() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {
            //alert(ret);扫码的结果都是编码
            //1：设备编码
            if (idSelector == 'equipCode') {

                $("#equipCode").val(ret);
                //查询仓库
                //getWorkCenter(ret, idSelector);
            }
        });
    }


    //查询
    function doSearch() {
        var person = $("#description").val()
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getEquipPersonList";
        var data = {
            values: {
                person: person,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    if (list) {
                        //遍历
                        for (var i = 0; i < list.length; i++) {
                            html += "<tr style='text-align: center;font-size: 12px;height:30px;'>";
                            html += "<td><input name='sub' type='checkbox' /></td>";
                            html += "<td name='code' style='display:none;'>" + list[i].code + "</td>";
                            html += "<td name='name'>" + list[i].name + "</td>";
                            html += "<td name='status'>" + list[i].status + "</td>";
                            html += "<td name='wait'>" + list[i].wxqty + "</td>";
                            html += "<td name='ing'>" + list[i].wxzqty + "</td>";
                            html += "</tr>";
                        }
                    }

                    $api.html($api.byId("tbodyHtml"), html);
                    //失败
                } else if (myobj.code == "1") {
                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }
    function save() {
        //选中数据
        var check = $("input[name='sub']:checked");
        var count = 0;
        var codeStr = "";
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            personCode = row.find("[name='code']").html();
            if (codeStr == "") {
                codeStr += personCode;
            } else {
                codeStr += "," + personCode;
            }
            count++;
        });
        if (count == 0) {
            api.toast({
                msg: "请选择派工人员数据!",
                duration: 3000
            });
            return;
        }
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/dispatchWork";
        var data = {
            values: {
                codeStr: codeStr,
                sysid: api.pageParam.sysid,
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {
                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });
                    api.closeToWin({ name: api.pageParam.name });
                    api.execScript({
                        name: api.pageParam.name,
                        script: 'doSearch()'
                    });
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }
    //订单返回按钮
    function closeWin() {
        api.closeWin({});
    }

</script>

</html>